<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        td {
            text-align: center
        }
        th {
            align-content: center;
        }
        li {
            list-style: none;
        }
    </style>
</head>
<body>
  <div >
      <p id="p1" style="left: 100px"></p>
      <table style="height: 70px;width: 600px;" >
          <th>现有确诊</th>
          <th>无症状者</th>
          <th>累计确诊</th>
          <th>境外输入</th>
          <tr id="tr1" >
          </tr>
      </table>
      <table style="height: 70px;width: 610px;" >
          <th>累计治愈</th>
          <th>累计死亡</th>
          <th>高风险地区</th>
          <th>中风险地区</th>
          <tr id="tr2" >
          </tr>
      </table>
      <p>高风险地区</p>
      <ul id="ul1">

      </ul>
      <p>中风险地区</p>
      <ul id="ul2">

      </ul>
  </div>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>

<script>
    var tianxing = 'http://api.tianapi.com/txapi/ncov/index?key=dc63d063c49ab6d8944720b6eeeb5f99'   //自行去天行API注册获取key值
    var city = 'http://api.tianapi.com/txapi/ncovcity/index?key=dc63d063c49ab6d8944720b6eeeb5f99'
    function timestampToTime(timestamp) {
        var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var Y = date.getFullYear() + '-';
        var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        var D = date.getDate() + ' ';
        var h = date.getHours() + ':';
        var m = date.getMinutes() + ':';
        var s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
    timestampToTime(1403058804);
    function fan(){

            $.ajax({
                type: "POST",
                url: "http://api.tianapi.com/ncov/index",
                data: {key: "dc63d063c49ab6d8944720b6eeeb5f99"},
                success: function(result) {
                    $("#p1").val(result)
                    console.log(result)
                    console.log(result.msg)
                    console.log(result.newslist[0].desc)
                    console.log(result.newslist[0].desc.currentConfirmedCount)
                    console.log(result.newslist[0].riskarea.high)
                    console.log(result.newslist[0].riskarea.mid)
                    var hss1='<td>'+result.newslist[0].desc.currentConfirmedCount+'<br>较昨日+'+result.newslist[0].desc.currentConfirmedIncr+'</td>' +
                        '<td>'+result.newslist[0].desc.currentConfirmedCount+'<br>较昨日+'+result.newslist[0].desc.seriousIncr+'</td>' +
                        '<td>'+result.newslist[0].desc.confirmedCount+'<br>较昨日+'+result.newslist[0].desc.confirmedIncr+'</td>' +
                        '<td>'+result.newslist[0].desc.suspectedCount+'<br>较昨日+'+result.newslist[0].desc.suspectedIncr+'</td>'
                    var hss2='<td>'+result.newslist[0].desc.curedCount+'<br>较昨日+'+result.newslist[0].desc.curedIncr+'</td>' +
                        '<td>'+result.newslist[0].desc.deadCount+'<br>较昨日+'+result.newslist[0].desc.deadIncr+'</td>' +
                        '<td>'+result.newslist[0].desc.highDangerCount+'</td>' +
                        '<td>'+result.newslist[0].desc.midDangerCount+'</td>'
                    var hss3='数据更新至'+timestampToTime(result.newslist[0].desc.modifyTime/1000)
                    var hss4=''
                    var hss5=''
                    for (let i = 0; i < result.newslist[0].riskarea.high.length; i++) {
                        hss4+='<li>'+result.newslist[0].riskarea.high[i]+'</li>'
                    }
                    for (let i = 0; i < result.newslist[0].riskarea.mid.length; i++) {
                        hss5+='<li>'+result.newslist[0].riskarea.mid[i]+'</li>'
                    }
                    $("#tr1").html(hss1)
                    $("#tr2").html(hss2)
                    $("#p1").html(hss3)
                    $("#ul1").html(hss4)
                    $("#ul2").html(hss5)
                },
                /* dataType: "jsonp",
                 crossDomain: true*/
                dataType: "json",

            });
    }
   fan();

</script>
</html>